/**
 * 客户退货查询管理初始化
 */
var CustomerReturnList = {
    id: "CustomerReturnListTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
CustomerReturnList.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '主键', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: '实付金额', field: 'amountPaid', visible: true, align: 'center', valign: 'middle'},
        {title: '应付金额', field: 'amountPayable', visible: false, align: 'center', valign: 'middle'},
        {title: '客户退货单号', field: 'returnOrderNumber', visible: true, align: 'center', valign: 'middle'},
        {title: '是否支付', field: 'payState', visible: true, align: 'center', valign: 'middle'},
        {title: '创建者', field: 'createBy', visible: false, align: 'center', valign: 'middle'},
        {title: '创建时间', field: 'createDate', visible: true, align: 'center', valign: 'middle'},
        {title: '更新者', field: 'updateBy', visible: false, align: 'center', valign: 'middle'},
        {title: '更新时间', field: 'updateDate', visible: false, align: 'center', valign: 'middle'},
        {title: '备注信息', field: 'remarks', visible: true, align: 'center', valign: 'middle'},
        {title: '删除标记（0：正常；1：删除）', field: 'delFlag', visible: false, align: 'center', valign: 'middle'},
        {title: '客户id', field: 'customerId', visible: false, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
CustomerReturnList.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length === 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        CustomerReturnList.seItem = selected[0];
        return true;
    }
};

/**
 * 设置dom中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
CustomerReturnList.setDomVal = function (key, val) {
    (typeof val === "undefined") ? $("#" + key).val('') : $("#" + key).val(val);
    return this;
}

/**
 * 清空查询条件
 */
CustomerReturnList.clear = function () {
    this
        .setDomVal('returnSaleOrderNumber')
        .setDomVal('payState')
        .setDomVal('remarks')
        .setDomVal('bDate')
        .setDomVal('eDate');
}
/**
 * 检查是否选中
 */
CustomerReturnList.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length === 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        CustomerReturnList.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加客户退货查询
 */
CustomerReturnList.openAddCustomerReturnList = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '添加客户退货查询',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/customerReturnList/customerReturnList_detail/' + + CustomerReturnList.seItem.id + '/' + CustomerReturnList.seItem.returnOrderNumber
        });
        this.layerIndex = index;
    }
};

/**
 * 打开查看客户退货查询详情
 */
CustomerReturnList.openCustomerReturnListDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '客户退货查询详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/customerReturnList/customerReturnList_update/' + CustomerReturnList.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除客户退货查询
 */
CustomerReturnList.delete = function () {
    if (this.check()) {
        var operaton = function () {
            var ajax = new $ax(Feng.ctxPath + "/customerReturn/delete", function (data) {
                Feng.success("删除成功!");
                CustomerReturnList.table.refresh();
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            ajax.set("customerReturnListId", CustomerReturnList.seItem.id);
            ajax.start();
        }
       Feng.confirm("是否删除退货订单? 该订单下的商品也会被删除.", operaton);
    }
};

/**
 * 查询客户退货查询列表
 */
CustomerReturnList.search = function () {
    var queryData = {};
    queryData['returnOrderNumber'] = $("#returnSaleOrderNumber").val();
    queryData['payState'] = $("#payState").val();
    queryData['remarks'] = $("#remarks").val();
    queryData['bDate'] = $("#bDate").val();
    queryData['eDate'] = $("#eDate").val();
    console.log('查找条件：', JSON.stringify(queryData));

    CustomerReturnList.table.refresh({query: queryData});
};

/**
 * 是否支付下拉框
 */
CustomerReturnList.isPaySelect = function () {
    $("#payState").html("<option value='1'>已支付</option>" +
        "<option value='0'>未支付</option>")
}


$(function () {
    var defaultColumns = CustomerReturnList.initColumn();
    var table = new BSTable(CustomerReturnList.id, "/customerReturn/list", defaultColumns);
    table.setTableHeight(0);
    table.setShowColumns(false);
    table.setShowRefresh(false);
    CustomerReturnList.table = table.init();
    //支付下拉框
    CustomerReturnList.isPaySelect();
});
